#include "search_good.h"
#include "ui_search_good.h"
#include "mainwindow.h"
#include "main.h"
#include <string>
#include <cstring>
search_good::search_good(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::search_good)
{
    ui->setupUi(this);
}

search_good::~search_good()
{
    delete ui;
}

void search_good::on_pushButton_clicked()
{
    std::string g_id = ui->lineEdit->text().toStdString();
    const char *id = g_id.c_str();
    goods_info *item;
    item = g_first;
    while(item){
        if(!strcmp(item->good_id, id)){
            const char* stock = std::to_string(item->stock).c_str();
            const char* sold = std::to_string(item->sold).c_str();
            const char* pre_p = std::to_string(item->prev_price).c_str();
            const char* disc = std::to_string(item->discount).c_str();
            const char* now_p = std::to_string(item->now_price).c_str();
            ui->lineEdit_2->setText(QString(item->good_name));
            ui->lineEdit_3->setText(QString(stock));
            ui->lineEdit_4->setText(QString(sold));
            ui->lineEdit_5->setText(QString(pre_p));
            ui->lineEdit_6->setText(QString(disc));
            ui->lineEdit_7->setText(QString(now_p));
            break;
        }else item = item->next;
    }
    if(!item){
        ui->lineEdit_2->setText(QString("None!"));
        ui->lineEdit_3->setText(QString("None!"));
        ui->lineEdit_4->setText(QString("None!"));
        ui->lineEdit_5->setText(QString("None!"));
        ui->lineEdit_6->setText(QString("None!"));
        ui->lineEdit_7->setText(QString("None!"));
    }
}
